import type { UserInfo } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace UserApi {
  export interface IPersonalInfo {
    avatar: null | string;
    created_at: string;
    created_by: number;
    email: string;
    id: number;
    is_online: number;
    name: string;
    phone: null;
    point: number;
    status: number;
    type: string;
    updated_at: string;
    username: string;
    [property: string]: any;
  }
  export interface CenterRequest {
    avatar?: string;
    conf_password?: string;
    email?: string;
    name: string;
    password?: string;
    phone?: string;
    username?: string;
    [property: string]: any;
  }
}

interface CenterRequest {
  avatar?: string;
  conf_password?: string;
  email?: string;
  name: string;
  password?: string;
  phone?: string;
  username?: string;
  [property: string]: any;
}

/**
 * 获取用户信息
 */
export async function getUserInfoApi() {
  return requestClient.get<UserInfo>('/user/info');
}

/*
  获取用户中心数据
*/
export async function getCenterApi() {
  return requestClient.get(`/center`);
}

/*
  更新用户中心数据
 */
export async function setCenterApi(id: number, data: any) {
  return requestClient.put<CenterRequest>(`/center/${id}`, data);
}
